package api

import (
	"github.com/gin-gonic/gin"
	"yun_image/api/middleware"
	"yun_image/config/api"
)

const Port = api.Port

var (
	router = gin.Default()
)

// startRoutes 注册路由
func startRoutes() {
	startUserApi()
	startImgApi()
	startWeiboApi()
	startCategoryApi()
	startChatRoomApi()
}

// useMiddlewares 注册中间件
func useMiddlewares() {
	middleware.UseCors(router)      //跨域
	middleware.UseIpLimit(router)   //验证ip合法性，比如请求是否过于频繁
	middleware.UseAuthorize(router) //身份验证
	middleware.UseWriteLog(router)  //记录日志
}

// RunServer 启动函数
func RunServer() {
	useMiddlewares()
	startRoutes()
	router.Run(Port)
}
